package adminService

import (
	"gitee.com/yangguoliang001/go-gin-vue3/BO"
	"github.com/gin-gonic/gin"
)

func (a *AdminService) MyAction(c *gin.Context, userID int32) (actionJsonData []BO.MyMenuActionListBO, err error) {
	// 查询当前用户对应的菜单id列表
	adminMenuList, err := a.adminMenuDao.WhereMenuIdByAdminId(userID)
	if err != nil {
		return nil, err
	}

	//
	var menuIds []int32
	for _, v := range adminMenuList {
		menuIds = append(menuIds, v.MenuId)
	}

	// 查询 menuId 对应的 action menu
	menuActionList, err := a.menuActionDao.QueryMenuActionAllList(menuIds)
	if err != nil {
		return nil, err
	}

	actionJsonData = make([]BO.MyMenuActionListBO, len(menuActionList))

	for k, v := range menuActionList {
		data := BO.MyMenuActionListBO{
			Id:     v.Id,
			MenuId: v.MenuId,
			Method: v.Method,
			Api:    v.Api,
		}
		actionJsonData[k] = data
	}
	return
}
